package com.lipiao.food;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.lipiao.food.Activity.MainActivity;
import java.util.List;

public class StepRecycleViewAdapter extends RecyclerView.Adapter<StepRecycleViewAdapter.ContactViewHolder> {
    //MyAdapter的成员变量contactInfoList, 这里被我们用作数据的来源
    private List<StepBean> stepBeanList;

    //构造函数
    public StepRecycleViewAdapter(List<StepBean> stepBeanList) {
        this.stepBeanList = stepBeanList;
    }

    //重写3个抽象方法
    @NonNull
    @Override
    public StepRecycleViewAdapter.ContactViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(viewGroup.getContext()).
                inflate(R.layout.step_card_item, viewGroup, false);
        return new ContactViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull StepRecycleViewAdapter.ContactViewHolder contactViewHolder, int i) {
        //i为当前card下标//foodbeanList中包含的都是foodbean类的对象 //通过其get()方法可以获得其中的对象
        StepBean stepBean = stepBeanList.get(i);
        //Log.d("1", "onBindViewHolder: "+stepBean.stepPicUrl+stepBean.stepTips);
        Glide.with(MainActivity.getContext()).load(stepBean.stepPicUrl).into(contactViewHolder.stepPic);
        contactViewHolder.stepTips.setText(stepBean.stepTips);
    }
    //自定义recycleView监听


    @Override
    public int getItemCount() {
        return stepBeanList.size();
    }

    //重点：该泛型必须是 自定义的适配器(如MyAdapter).ViewHolder
    class ContactViewHolder extends RecyclerView.ViewHolder {
        //create the viewHolder class
        protected ImageView stepPic;
        protected TextView stepTips;

        public ContactViewHolder(View itemView) {
            super(itemView);
            stepPic = itemView.findViewById(R.id.iv_step_pic);
            stepTips = itemView.findViewById(R.id.tv_step_tips);
        }
    }
}
